/*============================================================================*/
/*  Copyright (C) 2009-2011, iSOFT INFRASTRUCTURE SOFTWARE CO.,LTD.
 *  
 *  All rights reserved. This software is iSOFT property. Duplication 
 *  or disclosure without iSOFT written authorization is prohibited.
 *  
 *  
 *  @file       <Xcp_Internal.h>
 *  @brief      <Xcp Module internal H file. Declear all variables and functions
 *              used among all internal C files.>
 *  
 *  <Compiler: Codewarrior for mpc55xx v2.6     MCU:MPC56XX>
 *  
 *  @author     <Dongyuan.Sun, qitao.Yu>
 *  @date       <2013-03-06>
 */
/*============================================================================*/
#ifndef  XCP_INTERNAL_H
#define  XCP_INTERNAL_H

/*=======[R E V I S I O N   H I S T O R Y]====================================*/
/*  <VERSION>    <DATE>    <AUTHOR>     <REVISION LOG>
 *  V1.0.0       20130301  Dongyuan.Sun Initial version
 * 
 */
/*============================================================================*/

/*=======[I N C L U D E S]====================================================*/
#include "Xcp_Cfg.h"
#include "Os.h"

/*=======[M A C R O S]========================================================*/
#define XCP_PID_OFFSET             0x00u
/*
 * Command Code 
 */
/* Standard commands */
#define XCP_CMD_CONNECT                 0xFFu
#define XCP_CMD_DISCONNECT              0xFEu
#define XCP_CMD_GET_STATUS              0xFDu
#define XCP_CMD_SYNCH                   0xFCu
#define XCP_CMD_GET_COMM_MODE_INFO      0xFBu
#define XCP_CMD_GET_ID                  0xFAu
#define XCP_CMD_SET_REQUEST             0xF9u
#define XCP_CMD_GET_SEED                0xF8u
#define XCP_CMD_UNLOCK                  0xF7u
#define XCP_CMD_SET_MTA                 0xF6u
#define XCP_CMD_UPLOAD                  0xF5u
#define XCP_CMD_SHORT_UPLOAD            0xF4u
#define XCP_CMD_BUILD_CHECKSUM          0xF3u
#define XCP_CMD_TRANSPORT_LAYER_CMD     0xF2u
#define XCP_CMD_TL_SUB_CODE_OFFSET      0x01u
#define XCP_CMD_TL_GET_SLAVE_ID         0xFFu
#define XCP_CMD_TL_GET_DAQ_ID           0xFEu
#define XCP_CDM_TL_SET_DAQ_ID           0xFFu
#define XCP_CMD_USER_CMD                0xF1u

/* Calibration commands */
#define XCP_CMD_DOWNLOAD                0xF0u
#define XCP_CMD_DOWNLOAD_NEXT           0xEFu
#define XCP_CMD_DOWNLOAD_MAX            0xEEu
#define XCP_CMD_SHORT_DOWNLOAD          0xEDu
#define XCP_CMD_MODIFY_BITS             0xECu

/* Page switching commands */
#define XCP_CMD_SET_CAL_PAGE            0xEBu
#define XCP_CMD_GET_CAL_PAGE            0xEAu
#define XCP_CMD_GET_PAG_PROCESSOR_INFO  0xE9u
#define XCP_CMD_GET_SEGMENT_INFO        0xE8u
#define XCP_CMD_GET_PAGE_INFO           0xE7u
#define XCP_CMD_SET_SEGMENT_MODE        0xE6u
#define XCP_CMD_GET_SEGMENT_MODE        0xE5u
#define XCP_CMD_COPY_CAL_PAGE           0xE4u

/* Data acquisition and stimulation commands */
#define XCP_CMD_CLEAR_DAQ_LIST          0xE3u
#define XCP_CMD_SET_DAQ_PTR             0xE2u
#define XCP_CMD_WRITE_DAQ               0xE1u
#define XCP_CMD_SET_DAQ_LIST_MODE       0xE0u
#define XCP_CMD_GET_DAQ_LIST_MODE       0xDFu
#define XCP_CMD_START_STOP_DAQ_LIST     0xDEu
#define XCP_CMD_START_STOP_SYNCH        0xDDu
#define XCP_CMD_GET_DAQ_CLOCK           0xDCu
#define XCP_CMD_READ_DAQ                0xDBu
#define XCP_CMD_GET_DAQ_PROCESSOR_INFO  0xDAu
#define XCP_CMD_GET_DAQ_RESOLUTION_INFO 0xD9u
#define XCP_CMD_GET_DAQ_LIST_INFO       0xD8u
#define XCP_CMD_GET_DAQ_EVENT_INFO      0xD7u
#define XCP_CMD_FREE_DAQ                0xD6u
#define XCP_CMD_ALLOC_DAQ               0xD5u
#define XCP_CMD_ALLOC_ODT               0xD4u
#define XCP_CMD_ALLOC_ODT_ENTRY         0xD3u

/* Non-volatile memory programming commands */
#define XCP_CMD_PROGRAM_START           0xD2u
#define XCP_CMD_PROGRAM_CLEAR           0xD1u
#define XCP_CMD_PROGRAM                 0xD0u
#define XCP_CMD_PROGRAM_RESET           0xCFu
#define XCP_CMD_GET_PGM_PROCESSOR_INFO  0xCEu
#define XCP_CMD_GET_SECTOR_INFO         0xCDu
#define XCP_CMD_PROGRAM_PREPARE         0xCCu
#define XCP_CMD_PROGRAM_FORMAT          0xCBu
#define XCP_CMD_PROGRAM_NEXT            0xCAu
#define XCP_CMD_PROGRAM_MAX             0xC9u
#define XCP_CMD_PROGRAM_VERIFY          0xC8u

#define XCP_CMD_CODE_MIN                0xC8u

/*
 * End of Command Code
 */

#define XCP_RESP_ERROR_OFFSET           0x01u
#define XCP_RESP_POS_PID                0xFFu
#define XCP_RESP_ERR_PID                0xFEu

/* 
 * Error Code
 */
#define XCP_ERR_CMD_SYNCH               0x00u
#define XCP_ERR_CMD_BUSY                0x10u
#define XCP_ERR_DAQ_ACTIVE              0x11u
#define XCP_ERR_PGM_ACTIVE              0x12u
#define XCP_ERR_CMD_UNKNOWN             0x20u
#define XCP_ERR_CMD_SYNTAX              0x21u
#define XCP_ERR_OUT_OF_RANGE            0x22u
#define XCP_ERR_WRITE_PROTECTED         0x23u
#define XCP_ERR_ACCESS_DENIED           0x24u
#define XCP_ERR_ACCESS_LOCKED           0x25u
#define XCP_ERR_PAGE_NOT_VALID          0x26u
#define XCP_ERR_MODE_NOT_VALID          0x27u
#define XCP_ERR_SEGMENT_NOT_VALID       0x28u
#define XCP_ERR_SEQUENCE                0x29u
#define XCP_ERR_DAQ_CONFIG              0x2Au
#define XCP_ERR_MEMORY_OVERFLOW         0x30u
#define XCP_ERR_GENERIC                 0x31u
#define XCP_ERR_VERIFY                  0x32u
#define XCP_ERR_RES_TEMP_NOT_A          0x33u
/*
 * End of Error Code
 */

#define XCP_EV_PID              0xFDu
#define XCP_EV_CODE_OFFEST      0x01u
/*
 *  Event Code
 */
#define XCP_EV_RESUME_MODE          0x00u
#define XCP_EV_CLEAR_DAQ            0x01u
#define XCP_EV_STORE_DAQ            0x02u
#define XCP_EV_STORE_CAL            0x03u
#define XCP_EV_CMD_PENDING          0x05u
#define XCP_EV_DAQ_OVERLOAD         0x06u
#define XCP_EV_SESSION_TERMINATED   0x07u
#define XCP_EV_TIME_SYNC            0x08u
#define XCP_EV_STIM_TIMEOUT         0x09u
#define XCP_EV_SLEEP                0x0Au
#define XCP_EV_WAKE_UP              0x0Bu
#define XCP_EV_USER                 0xFEu
#define XCP_EV_TRANSPORT            0xFFu
/*
 * End of Event Code
 */

#define XCP_SERV_PID            0xFCu
#define XCP_SERV_CODE_OFFSET    0x01u

/*
 * Service Code
 */
#define XCP_SERV_RESET          0x00u
#define XCP_SERV_TEXT           0x01u
/*
 * End of Service Code
 */

/* Bitmask for SessionStatus */
#define XCP_SESSION_STATE_STORE_CAL     0x01u
#define XCP_SESSION_STATE_STORE_DAQ     0x04u
#define XCP_SESSION_STATE_CLEAR_DAQ     0x08u
#define XCP_SESSION_STATE_DAQ_RUNNING   0x40u
#define XCP_SESSION_STATE_RESUME        0x80u

/* Bitmasks for sendStatus */
#define XCP_RESP_REQUEST        0x01u
#define XCP_EV_REQUEST          0x02u
#define XCP_DAQ_REQUEST         0x04u
#define XCP_SERV_REQUEST        0x08u
#define XCP_SEND_REQUEST        0x0fu
#define XCP_RESP_PENDING        0x10u
#define XCP_EV_PENDING          0x20u
#define XCP_DAQ_PENDING         0x40u
#define XCP_SERV_PENDING        0x80u
#define XCP_SEND_PENDING        0xf0u
#define XCP_SEND_IDLE           0x00u

/* Bitmask for DAQ sendStatus */
#define XCP_DAQ_SS_ALTERNATING  0x01u
#define XCP_DAQ_SS_QUEUE        0x02u
#define XCP_DAQ_SS_SENDING      0x04u
#define XCP_DAQ_SS_OVERLOAD     0x08u
#define XCP_DAQ_SS_DONE         0x10u

/* Bitmask for DAQ mode */
#define XCP_DAQ_MOD_RESUME      0x80u
#define XCP_DAQ_MOD_RUNNING     0x40u
#define XCP_DAQ_MOD_PIDOFF      0x20u
#define XCP_DAQ_MOD_TS          0x10u
#define XCP_DAQ_MOD_DIRECTION   0x02u
#define XCP_DAQ_MOD_DIR_DAQ     0X00u
#define XCP_DAQ_MOD_DIR_STIM    0x02u
#define XCP_DAQ_MOD_SELECTED    0x01u
#define XCP_DAQ_MOD_ALTERNATING 0x01u


/* XCP checksum types */
#define XCP_CHECKSUM_TYPE_ADD_11        0x01u
#define XCP_CHECKSUM_TYPE_ADD_12        0x02u
#define XCP_CHECKSUM_TYPE_ADD_14        0x03u
#define XCP_CHECKSUM_TYPE_ADD_22        0x04u
#define XCP_CHECKSUM_TYPE_ADD_24        0x05u
#define XCP_CHECKSUM_TYPE_ADD_44        0x06u
#define XCP_CHECKSUM_TYPE_CRC_16        0x07u
#define XCP_CHECKSUM_TYPE_CRC_16_CITT   0x08u
#define XCP_CHECKSUM_TYPE_CRC_32        0x09u
#define XCP_CHECKSUM_TYPE_USER          0xFFu

#if (XCP_ADDRESS_GRANULARITY == XCP_AG_BYTE)
#define XCP_UPLOAD_DATA_OFFSET          (0x01u)
#elif (XCP_ADDRESS_GRANULARITY == XCP_AG_WORD)
#define XCP_UPLOAD_DATA_OFFSET          (0x02u)
#elif (XCP_ADDRESS_GRANULARITY == XCP_AG_DWORD)
#define XCP_UPLOAD_DATA_OFFSET          (0x04u)
#endif


#define XCP_PROGRAM_LEN_OFFSET  0x01u
#if (XCP_ADDRESS_GRANULARITY != XCP_AG_DWORD)
#define XCP_PROGRAM_DATA_OFFSET     0x02u
#else
#define XCP_PROGRAM_DATA_OFFSET     0x04u
#endif
#if (XCP_ADDRESS_GRANULARITY != XCP_AG_DWORD)
#define XCP_PROGRAM_SIZE            (((Xcp_LocalCfgPtr->XcpGernalRef->Xcp_MaxCtoPgm) - 2u)/XCP_AG)
#else
#define XCP_PROGRAM_SIZE            (((Xcp_LocalCfgPtr->XcpGernalRef->Xcp_MaxCtoPgm)/XCP_AG) - 0x01u)
#endif
#define XCP_PROGRAM_NEXT_SIZE       (XCP_PROGRAM_SIZE*(Xcp_LocalCfgPtr->XcpGernalRef->Xcp_MaxBsPgm))

#define XCP_DOWNLOAD_LEN_OFFSET 0x01u
#if (XCP_ADDRESS_GRANULARITY != XCP_AG_DWORD)
#define XCP_DOWNLOAD_DATA_OFFSET    0X02u
#else
#define XCP_DOWNLOAD_DATA_OFFSET    0X04u
#endif

#define XCP_DOWNLOADMAX_SIZE         (((Xcp_LocalCfgPtr->XcpGernalRef->Xcp_MaxCto)/XCP_AG) - 0x01u)
#if (XCP_ADDRESS_GRANULARITY != XCP_AG_DWORD)
#define XCP_DOWNLOAD_SIZE            (((Xcp_LocalCfgPtr->XcpGernalRef->Xcp_MaxCto) - 2u)/XCP_AG)
#else
#define XCP_DOWNLOAD_SIZE            (((Xcp_LocalCfgPtr->XcpGernalRef->Xcp_MaxCto)/XCP_AG) - 0x01u)
#endif
#define XCP_DOWNLOAD_NEXT_SIZE       (XCP_DOWNLOAD_SIZE*(Xcp_LocalCfgPtr->XcpGernalRef->Xcp_MaxBs))

#define XCP_UPLOAD_SIZE              (((Xcp_LocalCfgPtr->XcpGernalRef->Xcp_MaxCto)/XCP_AG) - 0x01u)

/*=======[T Y P E   D E F I N I T I O N S]====================================*/
#if (XCP_PL_DAQ == (XCP_PL_DAQ&XCP_RESOURCE)) 
typedef struct
{
    uint8   sendStatus;
    uint8   mode;     
    uint8   daqListSize;
    uint8   currentPid;
    #if (XCP_TIMESTAMP_TYPE != XCP_TS_NO_TS)
    TickType  timeStamp;
    #endif
    #if (XCP_DAQ_PRIORITY_SUPPORT == STD_ON)
    uint8   priority;
    #endif
    #if (XCP_PRESCALER_SUPPORTED == STD_ON)
    uint8   prescaler;
    uint8   prescalerCnt;    
    #endif
    #if (XCP_DAQ_CONFIG_TYPE == XCP_DAQ_DYNAMIC)
    Xcp_DaqCfgStatusType    cfgStatus;
    #endif
    uint8 firstPid;    
    uint16  eventChannelNum;
    uint32  eventBufferPos;
    P2VAR(Xcp_AGType, AUTOMATIC, XCP_VAR)        
            eventBufferPtr;
    P2VAR(Xcp_OdtType, AUTOMATIC, XCP_VAR)
            odt;
}Xcp_DaqType;

typedef struct
{
	uint32 bufferSize;
	uint32 bufferPos;
}Xcp_DynamicalDaqQueueType;

#endif /* (XCP_PL_DAQ == (XCP_PL_DAQ&XCP_RESOURCE))  */

typedef enum
{
    XCP_MEM_CAL_RAM = 0,
    XCP_MEM_CAL_ROM,
    XCP_MEM_CAL_ALL,
    XCP_MEM_ALL
}Xcp_AddressTypeType;

#if (XCP_MASTER_BLOCK_MODE == STD_ON)
typedef VAR(uint16,TYPEDEF) Xcp_BlockBufferIndexType;
#endif

#if (XCP_PL_PGM == (XCP_PL_PGM&XCP_RESOURCE))
/* Xcp program Status */
typedef enum 
{
	XCP_PGM_IDLE,
	XCP_PGM_START,
	XCP_PGM_CLEARED,
	XCP_PGM_PROGRAMMING,
	XCP_PGM_PROGRAMMED
}Xcp_PgmStautsType;
#endif

/*=======[E X T E R N A L   D A T A]==========================================*/
/*
 * Common Var.
 */

extern VAR(uint16, XCP_VAR) Xcp_SessionCfgId;

extern VAR(Xcp_StatusType, XCP_VAR) Xcp_Status;
extern P2CONST(Xcp_ConfigType, AUTOMATIC, XCP_VAR) Xcp_LocalCfgPtr;
extern VAR(Xcp_CommandStatusType, XCP_VAR) Xcp_CommandStatus;
extern VAR(uint8, XCP_VAR) Xcp_ProtectionStatus;
extern VAR(uint8, XCP_VAR) Xcp_SessionStatus;

extern VAR(uint8, XCP_VAR) Xcp_SendStatus;
extern VAR(uint8, XCP_VAR) Xcp_TransferTimeOutCnt;

extern VAR(uint8, XCP_VAR) Xcp_CmdBuffer[XCP_CTO_BUFFER_SIZE];
extern VAR(uint8, XCP_VAR) Xcp_RespBuffer[XCP_CTO_BUFFER_SIZE];
extern VAR(uint8, XCP_VAR) Xcp_EvBuffer[XCP_CTO_BUFFER_SIZE];
extern VAR(uint8, XCP_VAR) Xcp_ServBuffer[XCP_CTO_BUFFER_SIZE];
extern VAR(uint8, XCP_VAR) Xcp_DaqBuffer[XCP_DTO_BUFFER_SIZE];

extern VAR(PduLengthType, XCP_VAR) Xcp_CmdLength;
extern VAR(PduLengthType, XCP_VAR) Xcp_RespLength;
extern VAR(PduLengthType, XCP_VAR) Xcp_EvLength;

#if (XCP_SEED_AND_UNLOCK == STD_ON)
extern VAR(Xcp_SeedandKeyStatusType, XCP_VAR) Xcp_SeedandKeyStatus;
extern VAR(uint8, XCP_VAR) Xcp_SeedandKeyRes;
#endif


#if (XCP_PL_PGM == (XCP_PL_PGM&XCP_RESOURCE))
extern VAR(Xcp_PgmStautsType, XCP_VAR) Xcp_PgmStauts;
#endif

#if (XCP_SET_MTA == STD_ON)
extern VAR(Xcp_AddressType, XCP_VAR) Xcp_MTA;
#endif

#if (XCP_MASTER_BLOCK_MODE == STD_ON) 
extern VAR(Xcp_AGType, XCP_VAR) Xcp_BlockBuffer[XCP_BLOCK_BUFFER_SIZE];
#endif

#if (XCP_MASTER_BLOCK_MODE == STD_ON)||(XCP_SLAVE_BLOCK_MODE == STD_ON)
extern VAR(Xcp_BlockBufferIndexType, XCP_VAR) Xcp_BlockBufferPos;
extern VAR(Xcp_BlockBufferIndexType, XCP_VAR) Xcp_BlockBufferLen;
#endif /* (XCP_MASTER_BLOCK_MODE == STD_ON)||(XCP_SLAVE_BLOCK_MODE == STD_ON) */

#if ((XCP_GET_ID == STD_ON)\
    || (XCP_GET_DAQ_EVENT_INFO == STD_ON)\
    || (XCP_GET_SECTOR_INFO == STD_ON)\
    )
extern VAR(uint32, XCP_VAR) Xcp_UploadInfoLen;
#endif

#if (XCP_PL_CAL == (XCP_PL_CAL&XCP_RESOURCE))
#if (XCP_PAG_SUPPORT == STD_ON)
extern VAR(uint8, XCP_VAR) Xcp_ActivPagNum[XCP_MAX_SEGMENT];
#endif
#endif


#if (XCP_PL_DAQ == (XCP_PL_DAQ & XCP_RESOURCE))
extern VAR(Xcp_DaqType, XCP_VAR) Xcp_Daq[XCP_MAX_DAQ];
extern VAR(uint32, XCP_VAR) Xcp_EvChBufferUsage[XCP_MAX_EVENT_CHANNEL];
extern VAR(uint8, XCP_VAR) Xcp_EvChActivCnt[XCP_MAX_EVENT_CHANNEL];
#if (XCP_DAQ_PRIORITY_SUPPORT == STD_ON)
#if ((XCP_IDENTIFICATION_FIELD_TYPE == XCP_PID_ABSOLUTE) || (XCP_IDENTIFICATION_FIELD_TYPE == XCP_PID_RELATIVE_BYTE))
    extern VAR(uint8, XCP_VAR) Xcp_DaqListQueue[XCP_MAX_DAQ][2];
#else   /*XCP_IDENTIFICATION_FIELD_TYPE = RELATIVE_WORD or RELATIVE_WORD_ALIGNED */
    extern VAR(uint16, XCP_VAR) Xcp_DaqListQueue[XCP_MAX_DAQ][2];
#endif  /* XCP_IDENTIFICATION_FIELD_TYPE */
#else   /* XCP_DAQ_PRIORITY_SUPPORT == STD_OFF */
#if ((XCP_IDENTIFICATION_FIELD_TYPE == XCP_PID_ABSOLUTE) || (XCP_IDENTIFICATION_FIELD_TYPE == XCP_PID_RELATIVE_BYTE))
    extern VAR(uint8, XCP_VAR) Xcp_DaqListQueue[XCP_MAX_DAQ];
#else   /* XCP_IDENTIFICATION_FIELD_TYPE = RELATIVE_WORD or RELATIVE_WORD_ALIGNED */
    extern VAR(uint16, XCP_VAR) Xcp_DaqListQueue[XCP_MAX_DAQ];
#endif  /* XCP_IDENTIFICATION_FIELD_TYPE */
#endif  /* XCP_DAQ_PRIORITY_SUPPORT == STD_ON */
#if (XCP_DAQ_CONFIG_TYPE == XCP_DAQ_DYNAMIC)
extern VAR(uint8, XCP_VAR) Xcp_DynamicalDaqBuffer[XCP_DYNAMIC_DAQ_BUFFER_SIZE];
extern VAR(Xcp_DynamicalDaqQueueType, XCP_VAR) Xcp_DynamicalDaqQueue;
#endif

#if (XCP_GET_DAQ_CLOCK == STD_ON)
extern VAR(TickType, XCP_VAR)  Xcp_RxTimeStamp;
#endif /* XCP_GET_DAQ_CLOCK == STD_ON */

#endif  /* XCP_PL_DAQ == (XCP_PL_DAQ & XCP_RESOURCE) */


/*=======[E X T E R N A L   F U N C T I O N   D E C L A R A T I O N S]========*/
/* 
 * common services 
 */

extern FUNC(void, XCP_CODE) Xcp_CommandInit(void);
extern FUNC(void, XCP_CODE) Xcp_ClearStatus(void);

extern FUNC(void, XCP_CODE) Xcp_SetErrorCode(uint8 u1ErrorCode);
extern FUNC(void, XCP_CODE) Xcp_CopyU4ToU1Buffer(const uint32 u4Data, P2VAR(uint8,AUTOMATIC,XCP_VAR) pu1BufferPtr, uint8 byteOrder);
extern FUNC(void, XCP_CODE) Xcp_CopyU2ToU1Buffer(const uint16 u2Data, P2VAR(uint8,AUTOMATIC,XCP_VAR) pu1BufferPtr, uint8 byteOrder);
extern FUNC(void, XCP_CODE) Xcp_CopyU1BufferToU4(P2CONST(uint8,AUTOMATIC,XCP_VAR) pu1BufferPtr, P2VAR(uint32,AUTOMATIC,XCP_VAR) pu4Data, uint8 byteOrder);
extern FUNC(void, XCP_CODE) Xcp_CopyU1BufferToU2(P2CONST(uint8,AUTOMATIC,XCP_VAR) pu1BufferPtr, P2VAR(uint16,AUTOMATIC,XCP_VAR) pu2Data, uint8 byteOrder);
extern FUNC(void, XCP_CODE) Xcp_CalBufferCopy(uint32 u4SourceAddr, uint32 u4DestAddr, uint32 u4Length);

extern FUNC(Std_ReturnType, XCP_CODE) Xcp_Transmit (PduIdType pduId, PduLengthType len, P2VAR(uint8,AUTOMATIC,XCP_VAR) dataPtr);
extern FUNC(void, XCP_CODE) Xcp_SendResp(void);
extern FUNC(void, XCP_CODE) Xcp_SendEv(void);


/*
 * Command Service
 */

/*
 * STD
 */
/* Xcp STD mandatory commands */
extern FUNC(void, XCP_CODE) Xcp_Connect(void);
extern FUNC(void, XCP_CODE) Xcp_Disconnect(void);
extern FUNC(void,XCP_CODE) Xcp_DisconnectHal(void);
extern FUNC(void, XCP_CODE) Xcp_GetStatus(void);
extern FUNC(void, XCP_CODE) Xcp_Synch(void);

/* Xcp STD optional commands */
#if (XCP_GET_COMM_MODE_INFO == STD_ON)
extern FUNC(void, XCP_CODE) Xcp_GetCommModeInfo(void);
#endif
#if (XCP_GET_ID == STD_ON)
extern FUNC(void, XCP_CODE) Xcp_GetId(void);
#endif
#if (XCP_SET_REQUEST == STD_ON)
extern FUNC(void, XCP_CODE) Xcp_SetRequest(void);
#endif
#if (XCP_SEED_AND_UNLOCK == STD_ON)
extern FUNC(void, XCP_CODE) Xcp_GetSeed(void);
extern FUNC(void, XCP_CODE) Xcp_Unlock(void);
#endif
#if (XCP_SET_MTA == STD_ON)
extern FUNC(void, XCP_CODE) Xcp_SetMta(void);
extern FUNC(boolean, XCP_CODE) Xcp_CheckAddress(uint32 addr, uint32 size, Xcp_AddressTypeType type);
extern FUNC(void, XCP_CODE) Xcp_UpdateMTA(uint32 u4Length);
#endif
#if (XCP_UPLOAD == STD_ON)
extern FUNC(void, XCP_CODE) Xcp_Upload(void);
#endif
#if (XCP_SHORT_UPLOAD == STD_ON)
extern FUNC(void, XCP_CODE) Xcp_ShortUpload(void);
#endif
#if (XCP_BUILD_CHECKSUM == STD_ON)
extern FUNC(void,XCP_CODE) Xcp_BuildChecksum(void);
#endif
#if (XCP_GET_SLAVE_ID == STD_ON)
extern FUNC(void,XCP_CODE) Xcp_GetSlaveId(void);
#endif
#if (XCP_GET_DAQ_ID == STD_ON)
extern FUNC(void,XCP_CODE) Xcp_GetDaqId(void);
#endif
#if (XCP_USER_CMD == STD_ON)
extern FUNC(void,XCP_CODE) Xcp_UserCmd(void);
#endif

/*
 * End of STD Commands
 */


/*
 * CAL
 */
#if (XCP_PL_CAL == (XCP_PL_CAL & XCP_RESOURCE))
/*
 * CAL/PAG local Function
 */
extern FUNC(Std_ReturnType, XCP_CODE) Xcp_CALInit(void);

/*
 * CAL/PAG Mandatory Function
 */
extern FUNC(void, XCP_CODE) Xcp_Download(void);
/*
 * CAL/PAG Optional Function
 */
#if (XCP_DOWNLOAD_NEXT == STD_ON)
extern FUNC(void, XCP_CODE) Xcp_DownloadNext(void);
#endif
#if (XCP_DOWNLOAD_MAX == STD_ON)
extern FUNC(void, XCP_CODE) Xcp_DownloadMax(void);
#endif
#if (XCP_MODIFY_BITS == STD_ON)
extern FUNC(void, XCP_CODE) Xcp_ModifyBits(void);
#endif
#if (XCP_PAG_SUPPORT == STD_ON)
#if (XCP_SET_CAL_PAGE == STD_ON)
extern FUNC(void, XCP_CODE) Xcp_SetCalPage(void);
#endif
#if (XCP_GET_CAL_PAGE == STD_ON)
extern FUNC(void, XCP_CODE) Xcp_GetCalPage(void);
#endif
#endif
#endif /* (XCP_PL_CAL == (XCP_PL_CAL & XCP_RESOURCE)) */

/*
 * DAQ 
 */
#if (XCP_PL_DAQ == (XCP_PL_DAQ & XCP_RESOURCE))
extern FUNC(Std_ReturnType, XCP_CODE)Xcp_DAQInit(void); 
extern FUNC(void, XCP_CODE) Xcp_DAQReinit(void);
extern FUNC(void, XCP_CODE) Xcp_SendDaq(void);
extern FUNC(void, XCP_CODE) Xcp_EventChannelHandle(void);

#if (XCP_PL_STIM == (XCP_PL_STIM & XCP_RESOURCE))
extern FUNC(void, XCP_CODE)
#if (XCP_PID_OFF_SUPPORT  == STD_ON)
Xcp_RxStimHal
(const Xcp_DaqNumType daqListNum, const uint8 pid, const PduLengthType len, P2CONST(uint8,AUTOMATIC,XCP_APPL_DATA) dataPtr);
FUNC(Std_ReturnType,XCP_CODE) Xcp_FindDaqNum (CONST(PduIdType, AUTOMATIC) pduId,
                                          P2VAR(Xcp_DaqNumType, AUTOMATIC, XCP_VAR) daqNumPtr);
#else
Xcp_RxStimHal
(const uint8 pid, const PduLengthType len, P2CONST(uint8,AUTOMATIC,XCP_APPL_DATA) dataPtr);
#endif
#endif

/*
 * DAQ mandatory
 */
extern FUNC(void, XCP_CODE) Xcp_SetDaqPtr (void);
extern FUNC(void, XCP_CODE) Xcp_WriteDaq (void);
extern FUNC(void, XCP_CODE) Xcp_SetDaqListMode (void);
extern FUNC(void, XCP_CODE) Xcp_StartStopDaqList (void);
extern FUNC(void, XCP_CODE) Xcp_StartStopSynch (void);
#if (XCP_DAQ_CONFIG_TYPE == XCP_DAQ_STATIC)
extern FUNC(void, XCP_CODE) Xcp_ClearDaqList (void);
#if (XCP_GET_DAQ_LIST_INFO == STD_ON)
extern FUNC(void, XCP_CODE) Xcp_GetDaqListInfo(void);
#endif
#else
extern FUNC(void, XCP_CODE) Xcp_FreeDaq (void);
extern FUNC(void, XCP_CODE) Xcp_AllocDaq(void);
extern FUNC(void, XCP_CODE) Xcp_AllocOdt(void);
extern FUNC(void, XCP_CODE) Xcp_AllocOdtEntry(void);
#endif
/*
 * DAQ optional
 */
#if (XCP_GET_DAQ_CLOCK == STD_ON)
extern FUNC(void, XCP_CODE) Xcp_GetDaqClock (void);
#endif 
#if (XCP_GET_DAQ_PROCESSOR_INFO == STD_ON)
extern FUNC(void, XCP_CODE) Xcp_GetDaqProcessorInfo(void);
#endif
#if (XCP_GET_DAQ_RESOLUTION_INFO == STD_ON)
extern FUNC(void, XCP_CODE) Xcp_GetDaqResolutionInfo(void);
#endif
#if (XCP_GET_DAQ_LIST_MODE == STD_ON)
extern FUNC(void, XCP_CODE) Xcp_GetDaqListMode(void);
#endif
#if (XCP_GET_DAQ_EVENT_INFO == STD_ON)
extern FUNC(void, XCP_CODE) Xcp_GetDaqEventInfo(void);
#endif
#if (XCP_READ_DAQ == STD_ON)
extern FUNC(void, XCP_CODE) Xcp_ReadDaq(void);
#endif
/*
 * End of DAQ
 */
#endif /*(XCP_PL_DAQ == (XCP_PL_DAQ & XCP_RESOURCE))*/

/*
 * PGM
 */
#if (XCP_PL_PGM == (XCP_PL_PGM & XCP_RESOURCE))
extern FUNC(void, XCP_CODE) Xcp_ProgramInit(void);
extern FUNC(void, XCP_CODE) Xcp_PgmPendingTask(void);
/*
 * PGM mandatory
 */
extern FUNC(void, XCP_CODE) Xcp_ProgramStart(void);
extern FUNC(void, XCP_CODE) Xcp_ProgramClear(void);
extern FUNC(void, XCP_CODE) Xcp_Program (void);
extern FUNC(void, XCP_CODE) Xcp_ProgramReset(void);
/*
 * PGM optional
 */
#if (XCP_GET_PGM_PROCESSOR_INFO == STD_ON)
extern FUNC(void, XCP_CODE) Xcp_GetPgmProcessorInfo(void);
#endif
#if (XCP_GET_SECTOR_INFO == STD_ON)
extern FUNC(void, XCP_CODE) Xcp_GetSectorInfo(void);
#endif
#if (XCP_PROGRAM_PREPARE == STD_ON)
extern FUNC(void, XCP_CODE) Xcp_ProgramPrepare(void);
#endif
#if (XCP_PROGRAM_FORMAT == STD_ON)
extern FUNC(void, XCP_CODE) Xcp_ProgramFormat(void);
#endif
#if (XCP_PROGRAM_NEXT == STD_ON)
extern FUNC(void, XCP_CODE) Xcp_ProgramNext(void);
#endif
#if (XCP_PROGRAM_MAX == STD_ON)
extern FUNC(void, XCP_CODE) Xcp_ProgramMax(void);
#endif
#if (XCP_PROGRAM_VERIFY == STD_ON)
extern FUNC(void, XCP_CODE) Xcp_ProgramVerify(void);
#endif
/*
 * End of PGM
 */
#endif /*(XCP_PL_PGM == (XCP_PL_PGM & XCP_RESOURCE))*/

#endif  /* endof XCP_INTERNAL_H */

/*=======[E N D   O F   F I L E]==============================================*/

